define(['vue'],
  function (Vue) {
    function render() {
      new Vue({
        el: '#list',
        filters: {
          fileLenFilter(val) {
            if (val) {
              return val.split(',').length
            }
            return 0
          }
        },
        data() {
          return {
            querylist: [
              { title: '项目名称', field: 'projName', name: 'ElInput' },
              { title: '项目编号', field: 'projCode', name: 'ElInput' },
              {
                title: '验收状态', field: 'checkState',
                name: 'ElSelect',
                options: $.dict.values('project_checkState'),
                props: {
                  multiple: true,
                  clearable: true
                },
                optionProps: {
                  value: 'value',
                  label: 'displayName'
                }
              },
              {
                title: '验收标识开始', field: 'checkFlagStartNum', name: 'ElInputNumber',
                props: {
                  controls: false
                }
              },
              {
                title: '验收标识结束', field: 'checkFlagEndNum', name: 'ElInputNumber',
                props: {
                  controls: false
                }
              },
              {
                title: '重要程度', field: 'level', name: 'ElSelect',
                options: $.dict.values('importance_status'),
                props: {
                  multiple: true,
                  clearable: true
                },
                optionProps: {
                  value: 'value',
                  label: 'displayName'
                }
              },
              {
                title: '项目类型', field: 'projType', name: 'ElSelect',
                options: $.dict.values('importance_status'),
                props: {
                  multiple: true,
                  clearable: true
                },
                optionProps: {
                  value: 'value',
                  label: 'displayName'
                }
              },
              {
                title: '项目分类', field: 'projCategory', name: 'ElSelect',
                options: $.dict.values('project_type'),
                props: {
                  multiple: true,
                  clearable: true
                },
                optionProps: {
                  value: 'value',
                  label: 'displayName'
                }
              },
              { title: '项目经理', field: 'pmName', name: 'ElInput', },
              {
                title: '验收完成时间', field: 'finishTime', name: 'ElDatePicker',
                props: {
                  type: 'daterange',
                  valueFormat: 'yyyy-MM-dd',
                  clearable: true
                }
              },
              { title: '验收证书编号', field: 'certificateNo', name: 'ElInput' },
              {
                title: '验收完成情况', field: 'completion', name: 'ElSelect',
                options: $.dict.values('project_completion'),
                props: {
                  multiple: true,
                  clearable: true
                },
                optionProps: {
                  value: 'value',
                  label: 'displayName'
                }
              },
            ],
            form: {
              type: '1',
              keywords: '',
              flagNoCheck: '',
              flagFinish: ''
            },
            columns: [
              { title: '序号', type: 'seq', width: 50 },
              { title: '项目名称', field: 'projName', sortable: true, className: 'link', minWidth: 100 },
              { title: '项目编号', field: 'projCode', sortable: true, minWidth: 100 },
              { title: '验收状态', field: 'checkState', formatter: ['dictFilter', 'project_checkState'], sortable: true, minWidth: 100 },
              { title: '验收标识', field: 'checkFlag', sortable: true, minWidth: 100 },
              { title: '项目周期', field: 'projectCycle', sortable: true, minWidth: 100 },
              { title: '项目类型', field: 'projType', formatter: ['dictFilter', 'project_type'], sortable: true, minWidth: 100 },
              { title: '项目分类', field: 'projCategory', formatter: ['dictFilter', 'project_category'], sortable: true, minWidth: 100 },
              { title: '总经费(万元)', field: 'totalFunds', sortable: true, minWidth: 120 },
              { title: '使用经费(万元)', field: 'actuallyFunds', sortable: true, minWidth: 120 },
              { title: '项目经理', field: 'pmName', sortable: true, minWidth: 100 },
              { title: '验收完成时间', field: 'finishTime', formatter: ['dayjsFilter'], sortable: true, minWidth: 120 },
              { title: '项目重要程度', field: 'level', formatter: ['dictFilter', 'importance_status'], sortable: true, minWidth: 120 },
              { title: '完成情况', field: 'completion', formatter: ['dictFilter', 'project_completion'], sortable: true, minWidth: 100 },
            ],
            gridOptions: {
              pagerConfig: true,
              sortConfig: {
                remote: true
              },
              proxyConfig: {
                sort: true,
                ajax: {
                  query: ({ page, sort }) => {
                    const params = {
                      pageIndex: page.currentPage,
                      pageSize: page.pageSize,
                      orderBy: sort.field,
                      sortBy: sort.order
                    }
                    if (params.type === '1') {
                      this.form.pmId = $.el.auth.user.id
                    } else {
                      this.form.pmId = ''
                    }
                    return $.elApi.projElcheckAcceptBase.acceptBaseListPage(params,this.form)
                    .then(res => res.data)
                  }
                }
              }
            }
          }
        },
        methods: {
          save(form) {
            if (form.finishTime) {
              form.finishTimeStart = form.finishTime[0]
              form.finishTimeEnd = form.finishTime[1]
            } else {
              form.finishTimeStart = ''
              form.finishTimeEnd = ''
            }
            this.form = Object.assign({}, this.form, form)
          },
          cellClick({ column, row }) {
            if (!(!column || column.field === 'projName')) return
            window.route.goto(
              `${ELMP.resource('index.html','tmzk_project_acceptance')}?id=${row.projId}&spm=m-2-30&tid=`,
              { useCache: false }
            )
          },
          search() {
            this.$refs.vxegrid.commitProxy('reload')
          },
          clear() {
            this.form = {
              type: '1',
              name: '',
              flagNoCheck: '',
              flagFinish: ''
            }
            this.$refs.advanced.clear()
            this.search()
          },
        }
      })
    }
    return {
      init: render
    }
  })